import allure
from airtest.core.api import *
from common.airtest.airtest_base import AirtestBase
from common.log.log import log
from config.conf import BASE_DIR


class OrderDetailsPage:
    """订单详情页"""

    @allure.step('订单详情页，取消订单')
    def cancel_of_order(self):
        """订单详情页，取消订单"""
        try:
            log.info('订单详情页，取消订单')
            pass
        except Exception as e:
            log.error(f'订单详情页，取消订单出现异常为：{e}')
            raise e

    @allure.step('订单详情页，立即付款')
    def immediate_payment(self):
        """订单详情页，立即付款"""
        try:
            log.info('订单详情页，立即付款')
            pass
        except Exception as e:
            log.error(f'订单详情页，立即付款出现异常为：{e}')
            raise e

    @allure.step('订单详情页，查看物流')
    def view_logistics(self):
        """订单详情页，查看物流"""
        try:
            log.info('订单详情页，查看物流')
            element = BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/查看物流.png"
            AirtestBase().click_5(element)
        except Exception as e:
            log.error(f'订单详情页，查看物流出现异常为：{e}')
            raise e

    @allure.step('订单详情页，再次购买')
    def buy_again(self):
        """订单详情页，再次购买"""
        try:
            log.info('订单详情页，再次购买')
            element = BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/再次购买.png"
            AirtestBase().click_5(element)
        except Exception as e:
            log.error(f'订单详情页，再次购买出现异常为：{e}')
            raise e

    @allure.step('订单详情页，联系客服')
    def contact_customer_service(self):
        """订单详情页，联系客服"""
        try:
            log.info('订单详情页，联系客服')
            element = BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/联系客服.png"
            AirtestBase().click_5(element)
        except Exception as e:
            log.error(f'订单详情页，联系客服出现异常为：{e}')
            raise e

    @allure.step('订单详情页：申请发票')
    def request_nvoice(self):
        """
        订单详情页：申请发票
        """
        try:
            log.info('订单详情页：申请发票')
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/申请发票.png")
        except Exception as e:
            log.error(f'订单详情页，申请发票出现异常为：{e}')
            raise e

    @allure.step('订单详情页：确认收货')
    def confirm_receipt(self):
        """
        订单详情页：确认收货
        """
        try:
            log.info('订单详情页：确认收货')
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/确认收货.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/确定.png")
            sleep(2)  # 等待系统处理
            return OrderDetailsPage()
        except Exception as e:
            log.error(f'订单详情页，确认收货出现异常为：{e}')
            raise e

    @allure.step('订单详情页：订单评价')
    def order_evaluation(self):
        """
        订单详情页：订单评价
        """
        try:
            log.info('订单详情页：订单评价')
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/订单评价.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/商品评价页/商品质量评价.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/商品评价页/物流速度评价.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/商品评价页/立即评价.png")
            sleep(2)  # 等待系统处理
            log.info('订单评价完成！')
            return OrderDetailsPage()
        except Exception as e:
            log.error(f'订单详情页，订单评价出现异常为：{e}')
            raise e

    @allure.step('订单详情页：申请退款')
    def apply_for_refund(self):
        """
        订单详情页：申请退款
        """
        try:
            log.info('订单详情页：申请退款')
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/订单详情页/申请退款.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/我的/我的订单/申请退款页/申请退款按钮.png")
        except Exception as e:
            log.error(f'订单详情页，申请退款出现异常为：{e}')
            raise e